package com.shjy.driver.delegate;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.shjy.driver.activity.DetailActivity;
import com.shjy.driver.jg.JGUtil;
import com.shjy.driver.util.Const;

/**
 * Created by wed on 2017/5/20.
 */

public class MainWebviewDelegate extends BaseWebviewDelegate {

    public MainWebviewDelegate(Context context) {
        super(context);
        mIntent = new Intent(context, DetailActivity.class);
    }

    /**
     * 抢单
     */
    @JavascriptInterface
    public void bid() {
        mIntent.putExtra("url", "driver/bid/bid_list.html");
        mContext.startActivity(mIntent);
    }

    /**
     * 我的订单
     */
    @JavascriptInterface
    public void order() {
        mIntent.putExtra("url", "driver/order/order_list.html");
        mContext.startActivity(mIntent);
    }

    /**
     * 我的订单
     */
    @JavascriptInterface
    public void bill(String url) {
        mIntent.putExtra("url", url);
        mContext.startActivity(mIntent);
    }

    /**
     * 交运客服
     */
    @JavascriptInterface
    public void tel() {

        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + Const.TEL);
        intent.setData(data);
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        mContext.startActivity(intent);
    }

    /**
     * 我的订单跳转到订单详情页
     */
    @JavascriptInterface
    public void goOrderDetail(String url) {
        mIntent.putExtra("url", url);
        mContext.startActivity(mIntent);
    }

}
